<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除用户标签关联表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .section h3 {
            margin-top: 0;
            color: #666;
        }
        button {
            background-color: #dc3545;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #c82333;
        }
        button:disabled {
            background-color: #6c757d;
            cursor: not-allowed;
        }
        .result {
            margin-top: 15px;
            padding: 10px;
            border-radius: 4px;
            white-space: pre-wrap;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
        .warning {
            background-color: #fff3cd;
            color: #856404;
            border: 1px solid #ffeaa7;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>删除用户标签关联表和相关数据</h1>
        
        <div class="section">
            <h3>⚠️ 警告</h3>
            <p style="color: red; font-weight: bold;">
                此操作将永久删除用户标签关联表(tb_user_tag)和所有相关数据，包括：
            </p>
            <ul>
                <li>tb_user_tag 数据库表及其所有数据</li>
                <li>相关的菜单权限配置</li>
                <li>角色菜单关联数据</li>
            </ul>
            <p style="color: red;">此操作不可逆，请确认后再执行！</p>
        </div>

        <div class="section">
            <h3>1. 检查当前数据</h3>
            <button onclick="checkCurrentData()">检查tb_user_tag表状态</button>
            <div id="checkResult" class="result"></div>
        </div>

        <div class="section">
            <h3>2. 删除数据库表</h3>
            <button onclick="dropTable()" style="background-color: #dc3545;">删除tb_user_tag表</button>
            <div id="dropResult" class="result"></div>
        </div>

        <div class="section">
            <h3>3. 清理菜单权限</h3>
            <button onclick="cleanMenus()" style="background-color: #dc3545;">删除相关菜单权限</button>
            <div id="menuResult" class="result"></div>
        </div>

        <div class="section">
            <h3>4. 验证删除结果</h3>
            <button onclick="verifyDeletion()">验证删除结果</button>
            <div id="verifyResult" class="result"></div>
        </div>
    </div>

    <script>
        const baseURL = 'http://localhost:8080';

        function showResult(elementId, message, type = 'info') {
            const element = document.getElementById(elementId);
            element.textContent = message;
            element.className = `result ${type}`;
        }

        function showLoading(elementId) {
            showResult(elementId, '正在执行...', 'info');
        }

        async function checkCurrentData() {
            showLoading('checkResult');
            try {
                // 检查用户标签关联API是否还存在
                const response = await fetch(`${baseURL}/homepage/usertag/list`);
                if (response.status === 404) {
                    showResult('checkResult', '✅ 用户标签关联API已删除 (404 Not Found)', 'success');
                } else {
                    showResult('checkResult', `⚠️ 用户标签关联API仍然存在 (状态码: ${response.status})`, 'warning');
                }
            } catch (error) {
                if (error.message.includes('Failed to fetch')) {
                    showResult('checkResult', '✅ 用户标签关联API已删除 (连接失败)', 'success');
                } else {
                    showResult('checkResult', `检查失败: ${error.message}`, 'error');
                }
            }
        }

        async function dropTable() {
            showLoading('dropResult');
            try {
                // 这里需要调用后端API来删除表
                showResult('dropResult', '需要通过数据库管理工具手动删除tb_user_tag表', 'warning');
            } catch (error) {
                showResult('dropResult', `删除失败: ${error.message}`, 'error');
            }
        }

        async function cleanMenus() {
            showLoading('menuResult');
            try {
                // 这里需要调用后端API来清理菜单
                showResult('menuResult', '需要通过数据库管理工具手动删除相关菜单权限', 'warning');
            } catch (error) {
                showResult('menuResult', `清理失败: ${error.message}`, 'error');
            }
        }

        async function verifyDeletion() {
            showLoading('verifyResult');
            try {
                // 这里需要调用后端API来验证删除结果
                showResult('verifyResult', '请手动验证删除结果', 'warning');
            } catch (error) {
                showResult('verifyResult', `验证失败: ${error.message}`, 'error');
            }
        }

        // 页面加载时显示警告
        window.onload = function() {
            console.log('删除用户标签关联表工具已加载');
        };
    </script>
</body>
</html>
